package cn.ms.doctor.Configuration;

import cn.ms.doctor.Wrapper.MapWrapperFactory;
import com.alibaba.druid.pool.DruidDataSource;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class BaseConfiguration {
    @ConfigurationProperties("spring.datasource")
    @Bean
    public DataSource getDruidDatasource(){
        return new DruidDataSource();
    }

    /**
     * 解决mybatisMap不能驼峰命名
     * @return
     */
    @Bean
    public ConfigurationCustomizer mybatisConfigurationCustomizer(){
        return new ConfigurationCustomizer() {
            @Override
            public void customize(org.apache.ibatis.session.Configuration configuration) {
                configuration.setObjectWrapperFactory(new MapWrapperFactory());
            }
        };
    }
}
